// dynamic_cast
#include <iostream>
#include <exception>
using namespace std;

class CBase { virtual void dummy() {} };
class CDerived: public CBase { int a; };

// const_cast
void myprint (const char * str)
{
		//	(*str)='a'; // not able to change even if the str is from const_cast
		cout << str << endl;
}

unsigned short Hash( void *p ) {
   unsigned long long val = reinterpret_cast<unsigned long long>( p );
   // unsigned int val = (unsigned int)( p );
   return ( unsigned short )( val ^ (val >> 16));
}


int main () {
  
	cout << "sizeof int " << sizeof (int) <<endl;	
	cout << "sizeof void* " << sizeof (void*) <<endl;	
	try {
    CBase * pba = new CDerived;
    CBase * pbb = new CBase;
    CDerived * pd;
	const char * c = "sample text";
  	myprint( const_cast<char *> (c) );
  	myprint( (c) );
	
    // pd = dynamic_cast<CDerived*>(pba);
     pd = (CDerived*)(pba);
    if (pd==0) cout << "Null pointer on first type-cast" << endl;

    // pd = dynamic_cast<CDerived*>(pbb);
     pd = (CDerived*)(pbb); // no exception thrown, and pd != NULL
    if (pd==0) cout << "Null pointer on second type-cast" << endl;

  } catch (exception& e) {cout << "Exception: " << e.what();}

  int a[20];
   for ( int i = 0; i < 20; i++ )
      cout << Hash( a + i ) << endl;

  return 0;
}
